package com.ruoyi.hr.controller.hr.entryexitmanage.retiremanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.service.PublicService;
import com.ruoyi.hr.service.entryexitmanage.retiremanage.RetireManageService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author yuanwei
 * @explain 员工退休登记
 * @date 2020/4/14
 */
@Controller
@RequestMapping("entryExitManage/retireManage")
public class RetireManageController extends BaseController {

    private String prefix = "hr/entryexitmanage/retiremanage";

    @Autowired
    private RetireManageService retireManageService;

    @Autowired
    private PublicService publicService;

    @GetMapping
    public String retireManage() {
        return prefix + "/retireManage";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findRetireList(@RequestParam Map map) {
        return getDataTable(retireManageService.findRetireList(map));
    }

    @GetMapping("/add")
    public String add() {
        return prefix + "/addRetire";
    }

    @PostMapping("/addRetire")
    @ResponseBody
    public TableDataInfo addRetire(@RequestParam Map map) {
        return getDataTable(publicService.addPerson(map));
    }

    @PostMapping("/addRetireProcedure")
    @ResponseBody
    public BaseResult addRetireProcedure(String allEid, String allName) {
        return publicService.procedure(allEid, allName, "eSP_LeaveAddEmp", "2");
    }

    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String allName, String procedure) {
        return publicService.procedure(allId, allName, procedure);
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("editRetire", retireManageService.findRetire(id));
        return prefix + "/editRetire";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult updateRetire(@RequestParam Map map) {
        return toAjax(retireManageService.updateRetire(map));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int num = retireManageService.remove(ids);
        if (num == 0) {
            return error("删除中存在已确认信息，请取消确认后删除！");
        }
        return toAjax(num);
    }

    @GetMapping("/retireHistory")
    public String retireHistory() {
        return prefix + "/retireHistory";
    }

    @PostMapping("/retireHistory")
    @ResponseBody
    public TableDataInfo retireHistory(@RequestParam Map map) {
        return getDataTable(retireManageService.findRetireHistoryList(map));
    }
}
